package com.hopital5.zhangyz.controller;

import com.hopital5.zhangyz.model.Model;
import com.hopital5.zhangyz.repository.ModelRepository;
import com.hopital5.zhangyz.service.ModelService;
import com.hopital5.zhangyz.vo.response.ModelVoResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

@RestController
@RequestMapping("/model")
public class ModelController extends BaseController {
    @Autowired
    ModelService modelService;
    @Autowired
    ModelRepository modelRepository;

    @PostConstruct
    public void init() {
        modelRepository.save(Model.builder()
                .build());
    }

    @GetMapping("/detail/{modelId}")
    public ModelVoResponse detail(@PathVariable Long modelId) {
        return ModelVoResponse.build(modelService.findOne(modelId));
    }
}
